package com.sdp.wx.db.wx_repair_vehicle_wz.service.impl;

import com.sdp.wx.db.wx_repair_vehicle.entity.WxRepairVehicle;
import com.sdp.wx.db.wx_repair_vehicle_wz.entity.WxRepairVehicleWz;
import com.sdp.wx.db.wx_repair_vehicle_wz.mapper.WxRepairVehicleWzMapper;
import com.sdp.wx.db.wx_repair_vehicle_wz.service.IWxRepairVehicleWzService;
import com.sdp.wx.view.WxRepairMustWzView;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2024-01-19
 */
@Service
public class WxRepairVehicleWzServiceImpl extends ServiceImpl<WxRepairVehicleWzMapper, WxRepairVehicleWz> implements IWxRepairVehicleWzService {

	@Override
	public List<WxRepairVehicleWz> queryWxRepairVehicleWzByRepairCode(String repairCode) {
		LambdaQueryWrapper<WxRepairVehicleWz> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WxRepairVehicleWz::getRepairCode, repairCode);
		return list(queryWrapper);
	}

	@Override
	public void addMustRepairVehicleWz(List<WxRepairMustWzView> mustWzList, WxRepairVehicle repairVehicle) {
		List<WxRepairVehicleWz> wzs = new ArrayList<>();
		for(WxRepairMustWzView v : mustWzList) {
			WxRepairVehicleWz wz = new WxRepairVehicleWz();
			wz.setWzType(v.getWzType());
			wz.setWzName(v.getWzName());
			wz.setWzNo(v.getWzNo());
			wz.setWzModel(v.getWzModel());
			wz.setRepairCode(repairVehicle.getRepairCode());
			wz.setPickNum(BigDecimal.ONE);
			wz.setOutputNum(BigDecimal.ZERO);
			wz.setNotOutputNum(BigDecimal.ONE);
			wz.setWzUnit(v.getWzUnit());
			wzs.add(wz);
		}
		saveBatch(wzs);
	}

	@Override
	public int queryWxRepairVehicleWzCountByRepairCode(String repairCode) {
		LambdaQueryWrapper<WxRepairVehicleWz> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WxRepairVehicleWz::getRepairCode, repairCode);
		return count(queryWrapper);
	}

}
